<!-- 绿色通道 - 患者列表 - 医疗记录 - 基本信息(旧) 界面 -->
<template>
  <div class="info">
    <div class="topLine">
      <div class="blueDot" />
      <div style="float: left; margin-top: 8px">
        <span style="text-align: left; font-size: 20px; margin-left: 8px">
          卒中患者新增
        </span>
      </div>
      <div class="fanhui_btn" style="float: right">
        <el-button type="info" plain @click="routerBack()">
          <span class="iconfont icon-fanhui" />
          返回
        </el-button>
      </div>
      <div style="clear: both" />
    </div>

    <el-form
      ref="patientForm"
      style="padding-top: 20px; width: 95%; margin: auto"
      :model="patientForm"
      label-width="128px"
    >
      <el-row class="form-row" type="flex">
        <el-form-item label="住院ID">
          <el-input v-model="patientForm.inpatientId" size="mini" />
        </el-form-item>
        <el-form-item label="门诊ID">
          <el-input v-model="patientForm.outpatientId" size="mini" />
        </el-form-item>
        <el-form-item label="发病时间">
          <el-date-picker
            v-model="patientForm.incidentDateTime"
            type="datetime"
            size="mini"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <div v-if="false" class="equal-row-height">
          <el-checkbox v-model="patientForm.a">
            发病时间无法精确到分钟
          </el-checkbox>
        </div>
        <div v-if="false" class="equal-row-height not-accurate-minutes">
          <el-select v-model="patientForm.a1" size="mini" clearable>
            <el-option
              v-for="item in approximateTime"
              :key="'approximateTime' + item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </div>
      </el-row>
      <el-row class="form-row" type="flex">
        <el-form-item label="发病地址">
          <el-select
            v-model="patientForm.incidentProvince"
            size="mini"
            filterable
            clearable
            @change="provinceChange('incident')"
          >
            <el-option
              v-for="(area, index) in areaList"
              :key="'发病地址' + index"
              :value="area.name"
            />
          </el-select>
        </el-form-item>
        <div class="equal-row-height">
          <el-select
            v-model="patientForm.incidentCity"
            size="mini"
            clearable
            @change="cityChange('incident')"
          >
            <el-option
              v-for="(city, index) in getCity('incidentProvince')"
              :key="'发病地址(市)' + index"
              :value="city.name"
            />
          </el-select>
        </div>
        <div class="equal-row-height">
          <el-select v-model="patientForm.incidentArea" size="mini" clearable>
            <el-option
              v-for="(city, index) in getArea(
                'incidentCity',
                'incidentProvince'
              )"
              :key="'发病地址(区)' + index"
              :value="city.name"
            />
          </el-select>
        </div>
        <div class="equal-row-height long-text">
          <el-input
            v-model="patientForm.incidentaddress"
            size="mini"
            placeholder="输入详细地址"
          />
        </div>
      </el-row>
      <el-row type="flex">
        <el-form-item v-if="false" label="来院时间">
          <el-date-picker
            v-model="patientForm.d"
            type="datetime"
            size="mini"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
      </el-row>
      <el-row type="flex">
        <el-form-item label="患者姓名">
          <el-input v-model="patientForm.name" size="mini" />
        </el-form-item>
        <el-form-item label="性别" class="short-text">
          <el-select v-model="patientForm.sex" size="mini" clearable>
            <el-option value="男" />
            <el-option value="女" />
            <el-option value="未知" />
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" label-width="50px" class="short-text">
          <el-input v-model.number="patientForm.age" size="mini" />
        </el-form-item>
        <el-form-item label="身高" class="short-text">
          <el-input
            v-model="patientForm.height"
            size="mini"
            @input="BMI(patientForm.weight, patientForm.height)"
          />
        </el-form-item>
        <el-form-item label="体重" label-width="50px" class="short-text">
          <el-input
            v-model="patientForm.weight"
            size="mini"
            @input="BMI(patientForm.weight, patientForm.height)"
          />
        </el-form-item>
        <el-form-item label="BMI">
          <el-input v-model="patientForm.BMI" size="mini" />
        </el-form-item>
        <el-form-item label="出生日期">
          <el-date-picker
            v-model="patientForm.birthday"
            type="date"
            size="mini"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="updateAge"
          />
        </el-form-item>
      </el-row>
      <el-row type="flex">
        <el-form-item label="证件类型">
          <el-select
            v-model="patientForm.credentialstype"
            size="mini"
            clearable
          >
            <el-option label="无" value="0" />
            <el-option label="身份证" value="1" />
            <el-option label="护照" value="2" />
            <el-option label="军官证" value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="证件号码">
          <el-input v-model="patientForm.idcardid" size="mini" />
        </el-form-item>
        <el-form-item label="国籍">
          <el-select v-model="patientForm.nationality" size="mini" clearable>
            <el-option value="中国" />
            <el-option value="外国" />
          </el-select>
        </el-form-item>
        <el-form-item label="民族">
          <el-select
            v-model="patientForm.ethnicity"
            size="mini"
            filterable
            clearable
          >
            <el-option
              v-for="(nation, index) in nationList"
              :key="'民族' + index"
              :value="nation.nationName"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="婚姻状况">
          <el-select v-model="patientForm.maritalstatus" size="mini" clearable>
            <el-option value="未婚" />
            <el-option value="已婚" />
            <el-option value="丧偶" />
            <el-option value="离婚" />
          </el-select>
        </el-form-item>
      </el-row>
      <el-row type="flex">
        <el-form-item label="医保类型">
          <el-select
            v-model="patientForm.medicalinsurancetype"
            size="mini"
            clearable
          >
            <el-option value="1" label="城镇职工基本医疗保险" />
            <el-option value="3" label="城镇居民基本医疗保险" />
            <el-option value="2" label="新型农村合作医疗" />
            <el-option value="6" label="商业医疗保险" />
            <el-option value="7" label="全公费" />
            <el-option value="4" label="全自费" />
            <el-option value="8" label="其它社会保险" />
            <el-option value="9" label="贫困救助" />
          </el-select>
        </el-form-item>
        <el-form-item label="医保账号">
          <el-input v-model="patientForm.medicalinsuranceno" size="mini" />
        </el-form-item>
        <el-form-item label="文化程度">
          <el-select v-model="patientForm.culturedegree" size="mini" clearable>
            <el-option value="01" label="小学及以下" />
            <el-option value="03" label="初中" />
            <el-option value="04" label="中专/高中" />
            <el-option value="07" label="大专/本科" />
            <el-option value="08" label="硕士及以上" />
          </el-select>
        </el-form-item>
        <el-form-item label="职业">
          <el-select v-model="patientForm.job" size="mini" clearable>
            <el-option
              value="01"
              label="国家机关，党群组织，企事业单位负责人"
            />

            <el-option value="02" label="各类专业技术人员" />
            <el-option value="03" label="办事人员和有关人员" />
            <el-option value="04" label="商业及服务型工作人员" />
            <el-option value="05" label="农，林，牧，渔，水利业生产人员" />
            <el-option value="06" label="下岗或无业" />
            <el-option value="07" label="离退休" />
            <el-option value="08" label="学生" />
            <el-option value="09" label="军人" />
            <el-option value="10" label="不便分类的其他从业人员" />
          </el-select>
        </el-form-item>
      </el-row>

      <el-row type="flex">
        <el-form-item label="入院方式">
          <el-select
            v-model="patientForm.coming_institution_code"
            size="mini"
            clearable
          >
            <el-option value="1" label="急诊" />
            <el-option value="2" label="门诊" />
            <el-option value="3" label="其他医疗机构转入" />
            <el-option value="4" label="其他" />
          </el-select>
        </el-form-item>
        <el-form-item label="家属姓名">
          <el-input v-model="patientForm.familyName" size="mini" />
        </el-form-item>
        <el-form-item label="与患者关系">
          <el-input v-model="patientForm.familyRelation" size="mini" />
        </el-form-item>
        <el-form-item label="家属电话">
          <el-input v-model="patientForm.familyPhone" size="mini" />
        </el-form-item>
      </el-row>
      <el-row type="flex" class="form-row">
        <el-form-item label="户籍所在地">
          <el-select
            v-model="patientForm.idProvince"
            size="mini"
            filterable
            clearable
            @change="provinceChange('id')"
          >
            <el-option
              v-for="(area, index) in areaList"
              :key="'户籍所在地' + index"
              :value="area.name"
            />
          </el-select>
        </el-form-item>
        <div class="equal-row-height">
          <el-select
            v-model="patientForm.idCity"
            size="mini"
            clearable
            @change="cityChange('id')"
          >
            <el-option
              v-for="(city, index) in getCity('idProvince')"
              :key="'户籍所在地(市)' + index"
              :value="city.name"
            />
          </el-select>
        </div>
        <div class="equal-row-height">
          <el-select v-model="patientForm.idArea" size="mini" clearable>
            <el-option
              v-for="(city, index) in getArea('idCity', 'idProvince')"
              :key="'户籍所在地(区)' + index"
              :value="city.name"
            />
          </el-select>
        </div>
        <div class="equal-row-height long-text">
          <el-input
            v-model="patientForm.idaddress"
            size="mini"
            placeholder="输入详细地址"
          />
        </div>
      </el-row>
      <div class="line" />
      <el-row type="flex" class="in-hospital">
        <div class="title">在院卒中</div>
      </el-row>
      <el-row type="flex">
        <el-form-item label="发病地点" label-width="200px">
          <el-select v-model="patientForm.attackDepartment" size="mini">
            <el-option
              v-for="(dept, index) in deptList"
              :key="'dept' + index"
              :value="dept.name"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="会诊时间" label-width="200px">
          <el-date-picker
            v-model="patientForm.consultationTime"
            type="datetime"
            size="mini"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="离开发病现场时间" label-width="200px">
          <el-date-picker
            v-model="patientForm.leaveDepartmentTime"
            type="datetime"
            size="mini"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
      </el-row>
      <div class="line" />
      <el-row type="flex">
        <el-form-item label="来院方式">
          <div class="radio-div">
            <el-radio v-model="patientForm.comingWayCode" label="6">
              本院急救车
            </el-radio>
            <el-radio v-model="patientForm.comingWayCode" label="7">
              当地120
            </el-radio>
            <el-radio v-model="patientForm.comingWayCode" label="8">
              外院转院来院
            </el-radio>
            <el-radio v-model="patientForm.comingWayCode" label="9">
              自行来院
            </el-radio>
          </div>
        </el-form-item>
      </el-row>
      <el-row
        v-if="
          patientForm.comingWayCode == '6' || patientForm.comingWayCode == '7'
        "
      >
        <el-row type="flex">
          <el-form-item label="呼救时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.helpDate"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
        </el-row>
        <el-row type="flex">
          <el-form-item label="120派车时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.dispatch120Time"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="120出车时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.departure120Time"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="120到达现场时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.arrivalScene120Time"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="120离开现场时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.leaveScene120Time"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
        </el-row>
        <el-row type="flex">
          <el-form-item label="患者送达医院时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.arrivalTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="首次医疗接触时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.firstMedicalContactDateTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="院内首诊医师接诊时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.inhospitalAdmissionTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="医护人员" label-width="200px">
            <el-input
              v-model="patientForm.dispatchEmergens.cw120FirstDoctorName"
              size="mini"
            />
          </el-form-item>
        </el-row>
      </el-row>
      <el-row v-if="patientForm.comingWayCode == '8'">
        <el-row type="flex">
          <el-form-item label="转院类型" label-width="200px">
            <el-select
              v-model="patientForm.dispatchEmergens.cwZyTransType"
              size="mini"
            >
              <el-option value="1" label="网络医院" />
              <el-option value="2" label="其他医疗机构" />
            </el-select>
          </el-form-item>
          <el-form-item label="医院名称" label-width="200px">
            <el-input
              v-model="patientForm.dispatchEmergens.hospitalName"
              size="mini"
            />
          </el-form-item>
          <el-form-item label="首次医疗接触时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.firstMedicalContactDateTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
        </el-row>
        <el-row type="flex">
          <el-form-item label="转出医院入门时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.outhospitalVisitTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="决定转院时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.transferTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="转出医院出门时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.leaveOuthospitalTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
        </el-row>
        <el-row type="flex">
          <el-form-item label="到达医院大门时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.arrivalTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="院内接诊时间" label-width="200px">
            <el-date-picker
              v-model="patientForm.dispatchEmergens.inhospitalAdmissionTime"
              type="datetime"
              size="mini"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>

          <el-form-item label="医护人员" label-width="200px">
            <el-input
              v-model="patientForm.dispatchEmergens.cw120FirstDoctorName"
              size="mini"
            />
          </el-form-item>
        </el-row>
      </el-row>
      <el-row v-if="patientForm.comingWayCode == '9'">
        <el-row>
          <el-row type="flex">
            <el-form-item label="到达医院大门时间" label-width="200px">
              <el-date-picker
                v-model="patientForm.dispatchEmergens.arrivalTime"
                type="datetime"
                size="mini"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
            <el-form-item label="首次医疗接触时间" label-width="200px">
              <el-date-picker
                v-model="
                  patientForm.dispatchEmergens.firstMedicalContactDateTime
                "
                type="datetime"
                size="mini"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
            <el-form-item label="院内首诊医师接诊时间" label-width="200px">
              <el-date-picker
                v-model="patientForm.dispatchEmergens.inhospitalAdmissionTime"
                type="datetime"
                size="mini"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
            <el-form-item label="医护人员" label-width="200px">
              <el-input
                v-model="patientForm.dispatchEmergens.cw120FirstDoctorName"
                size="mini"
              />
            </el-form-item>
          </el-row>
        </el-row>
      </el-row>
      <div class="line" />
      <el-row
        type="flex"
        justify="center"
        style="padding-right: 40px; padding-top: 20px"
      >
        <el-button
          type="primary"
          style="width: 140px"
          @click="save"
        >保存</el-button>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import {
  selectRegionEx,
  getPatientStroke,
  savePatientInfo,
  getDepartmentList
} from '@/api/green-channel/info'
import { newDispatch } from '@/api/triage/triage-new'

export default {
  name: 'InfoStrokeNew',
  data() {
    return {
      areaList: [],
      persondata: {},
      url: [],
      patientForm: {
        dispatchEmergens: {}
      },
      comingWayCode: '',
      srcList: [],
      approximateTime: [
        { code: '1', name: '凌晨(0点到6点)' },
        { code: '2', name: '清晨(6到8点)' },
        { code: '3', name: '上午(8到12点)' },
        { code: '4', name: '中午(12到14点)' },
        { code: '5', name: '下午(14到17点)' },
        { code: '6', name: '傍晚(17到19点)' },
        { code: '7', name: '晚上(19到24点)' }
      ],
      nationList: [
        { nationCode: '01', nationName: '汉族' },
        { nationCode: '02', nationName: '蒙古族' },
        { nationCode: '03', nationName: '回族' },
        { nationCode: '04', nationName: '藏族' },
        { nationCode: '05', nationName: '维吾尔族' },
        { nationCode: '06', nationName: '苗族' },
        { nationCode: '07', nationName: '彝族' },
        { nationCode: '08', nationName: '壮族' },
        { nationCode: '09', nationName: '布依族' },
        { nationCode: '10', nationName: '朝鲜族' },
        { nationCode: '11', nationName: '满族' },
        { nationCode: '12', nationName: '侗族' },
        { nationCode: '13', nationName: '瑶族' },
        { nationCode: '14', nationName: '白族' },
        { nationCode: '15', nationName: '土家族' },
        { nationCode: '16', nationName: '哈尼族' },
        { nationCode: '17', nationName: '哈萨克族' },
        { nationCode: '18', nationName: '傣族' },
        { nationCode: '19', nationName: '黎族' },
        { nationCode: '20', nationName: '傈僳族' },
        { nationCode: '21', nationName: '佤族' },
        { nationCode: '22', nationName: '拉祜族' },
        { nationCode: '23', nationName: '高山族' },
        { nationCode: '24', nationName: '白族' },
        { nationCode: '25', nationName: '水族' },
        { nationCode: '26', nationName: '东乡族' },
        { nationCode: '27', nationName: '纳西族' },
        { nationCode: '28', nationName: '景颇族' },
        { nationCode: '29', nationName: '柯尔克孜族' },
        { nationCode: '30', nationName: '土族' },
        { nationCode: '31', nationName: '达斡尔族' },
        { nationCode: '32', nationName: '仫佬族' },
        { nationCode: '33', nationName: '羌族' },
        { nationCode: '34', nationName: '布朗族' },
        { nationCode: '35', nationName: '撒拉族' },
        { nationCode: '36', nationName: '毛南族' },
        { nationCode: '37', nationName: '仡佬族' },
        { nationCode: '38', nationName: '锡伯族' },
        { nationCode: '39', nationName: '阿昌族' },
        { nationCode: '40', nationName: '土族普米族' },
        { nationCode: '41', nationName: '塔吉克族' },
        { nationCode: '42', nationName: '怒族' },
        { nationCode: '43', nationName: '乌孜别克族' },
        { nationCode: '44', nationName: '俄罗斯族' },
        { nationCode: '45', nationName: '鄂温克族' },
        { nationCode: '46', nationName: '崩龙族' },
        { nationCode: '47', nationName: '保安族' },
        { nationCode: '48', nationName: '裕固族' },
        { nationCode: '49', nationName: '京族' },
        { nationCode: '50', nationName: '塔塔尔族' },
        { nationCode: '51', nationName: '独龙族' },
        { nationCode: '52', nationName: '鄂伦春族' },
        { nationCode: '53', nationName: '赫哲族' },
        { nationCode: '54', nationName: '门巴族' },
        { nationCode: '55', nationName: '珞巴族' },
        { nationCode: '56', nationName: '基诺族' },
        { nationCode: '97', nationName: '其他' },
        { nationCode: '98', nationName: '外国血统' }
      ],
      newInfo: {},
      deptList: []
    }
  },
  watch: {
    'patientForm.comingWayCode': {
      handler(val) {
        if (this.comingWayCode !== '6' && this.comingWayCode !== '7') {
          if (val === this.comingWayCode) {
          } else {
            for (const key in this.patientForm.dispatchEmergens) {
              if (
                key !== 'firstMedicalContactDateTime' &&
                key !== 'inhospitalAdmissionTime' &&
                key !== 'cw120FirstDoctorName'
              ) {
                this.patientForm.dispatchEmergens[key] = ''
              }
            }
          }
        } else {
          if (val === '6' || val === '7') {
          } else {
            this.patientForm.dispatchEmergens.cwZyTransType = ''
            this.patientForm.dispatchEmergens.hospitalName = ''
            this.patientForm.dispatchEmergens.outhospitalVisitTime = ''
            this.patientForm.dispatchEmergens.transferTime = ''
            this.patientForm.dispatchEmergens.leaveOuthospitalTime = ''
            this.patientForm.dispatchEmergens.arrivalTime = ''
          }
        }
      }
    }
  },
  created() {
    this.selectRegionEx()
    this.getDepartmentList()
  },
  methods: {
    updateAge(birthday) {
      if (this.patientForm.birthday) {
        const birYear = new Date(this.patientForm.birthday).getFullYear()
        const birTime = new Date(this.patientForm.birthday).getTime()
        const thisYear = new Date().getFullYear()
        const thisTime = new Date().getTime()
        if (birTime > thisTime) {
          this.$message.warning('出生日期不能大于当前日期')
          this.patientForm.birthday = ''
          return
        }
        this.$set(this.patientForm, 'age', thisYear - birYear)
      }
    },
    getDepartmentList() {
      getDepartmentList(this.$store.getters.hospitalId).then((res) => {
        this.deptList = res.data
      })
    },
    save() {
      let whether = true
      if(!this.patientForm.incidentDateTime){
        this.$message.warning('发病时间必须填写!')
        whether = false
      }else if(!this.patientForm.incidentProvince){
        this.$message.warning('发病地址必须填写!')
        whether = false
      }else if(!this.patientForm.incidentCity){
        whether = false
        this.$message.warning('发病地址必须填写!')
      }else if(!this.patientForm.incidentArea){
        whether = false
        this.$message.warning('发病地址必须填写!')
      }else if(!this.patientForm.incidentaddress){
        whether = false
        this.$message.warning('发病详细地址必须填写!')
      }else if(!this.patientForm.name){
        whether = false
        this.$message.warning('姓名必须填写!')
      }else if(!this.patientForm.sex){
        whether = false
        this.$message.warning('性别必须填写!')
      }else if(!this.patientForm.age){
        whether = false
        this.$message.warning('年龄必须填写!')
      }else if(!this.patientForm.comingWayCode){
        whether = false
        this.$message.warning('来院方式必须选择!')

      }else if(this.patientForm.comingWayCode == '6' || this.patientForm.comingWayCode == '7'){
        if(!this.patientForm.dispatchEmergens.arrivalTime){
          whether = false
          this.$message.warning('患者送达医院时间必须填写!')
        }
      }else if(this.patientForm.comingWayCode == '8' || this.patientForm.comingWayCode == '9'){
        if(!this.patientForm.dispatchEmergens.arrivalTime){
          whether = false
          this.$message.warning('到达医院大门时间必须填写!')
        }
      }
      if(whether){
        newDispatch({
          apiToken: this.$store.getters.apiToken,
          greenType: '卒中'
        }).then((res) => {
          if (res.code === 0) {
            const obj = res.data
            this.patientForm.patientId = obj.patientId
            getPatientStroke(res.data.patientId, res.data.dispatchId).then(
              (res) => {
                if (res.code === 0) {
                  this.newInfo = res.data
                  this.savePatient({
                    dispatchId: obj.dispatchId,
                    patientId: obj.patientId
                  })
                } else {
                  this.$message.error('保存失败')
                }
              }
            )
          } else {
            this.$message.error('保存失败')
          }
        })
      }
    },
    savePatient(obj) {
      savePatientInfo({ ...this.newInfo, ...this.patientForm, ...obj }).then(
        (res) => {
          if (res.code === 0) {
            this.$message.success('保存成功')
            const data = {
              name: 'patientsList',
              sourcePage: 'InfoStrokeNew',
              greenType: '卒中', // 二选一
              patientId: obj.patientId
            }
            this.$router.push({
              name: 'patientsList',
              params: data
            })
          } else {
            this.$message.error('保存失败')
          }
        }
      )
    },
    routerBack() {
      this.$router.push({
        name: 'patientsList',
        params: {
          greenType: '卒中'
        }
      })
    },
    selectRegionEx() {
      selectRegionEx().then((res) => {
        this.areaList = res.data
      })
    },
    BMI(weight, height) {
      let num = 0
      if (weight && height) {
        num = weight / ((height * height) / 10000)
      }
      if (num === 0) {
        this.patientForm.BMI = null
      } else {
        this.patientForm.BMI = num.toFixed(1)
      }
    },
    provinceChange(field) {
      this.$set(this.patientForm, field + 'City', '')
      this.$set(this.patientForm, field + 'Area', '')
    },
    cityChange(field) {
      this.$set(this.patientForm, field + 'Area', '')
    },
    getCity(field) {
      let city = []
      let arr = []
      if (this.patientForm[field]) {
        city = this.areaList.filter(
          (item) => item.name === this.patientForm[field]
        )

        if (city.length > 0) {
          arr = city[0].cityList
        }
      }
      return arr
    },
    getArea(field, provinceField) {
      let area = []
      let arr = []
      if (this.getCity(provinceField).length > 0 && this.patientForm[field]) {
        area = this.getCity(provinceField).filter(
          (item) => item.name === this.patientForm[field]
        )
        if (area.length > 0) {
          arr = area[0].areaList
        }
      }
      return arr
    }
  }
}
</script>
<style lang="scss" scoped>
.info {
  overflow-x: auto;
  min-height: 80vh;
  .equal-row-height {
    line-height: 36px;
  }
  .form-row {
    .equal-row-height {
      margin-left: 20px;
    }
  }
  .el-form-item {
    margin-bottom: 10px;
  }
  .in-hospital {
    .title {
      width: 128px;
      font-size: 14px;
      color: #606266;
      text-align: right;
      padding-right: 12px;
      line-height: 36px;
    }
  }
  .line {
    height: 1px;
    width: 100%;
    border-top: 1px dashed #dcdfe6;
    margin: 6px 0 9px 0;
  }
}
.topLine {
  background-color: rgb(255, 255, 255);
  color: rgb(57, 68, 85);
  overflow: hidden;
  z-index: 9999;
  padding: 10px 20px;
  text-align: center;
  border-bottom: 10px solid rgb(242, 242, 242);
}

.blueDot {
  width: 15px;
  height: 15px;
  line-height: 30px;
  background-color: rgb(67, 128, 234);
  border-radius: 50%;
  float: left;
  margin-top: 15px;
}
</style>
<style lang="scss">
.info {
  .el-form-item__label {
    font-weight: normal;
  }
  .not-accurate-minutes {
    .el-input__inner {
      width: 130px;
      min-width: unset;
    }
  }
  .short-text {
    .el-input__inner {
      width: 85px;
      min-width: unset;
    }
  }
  .el-input__inner {
    min-width: 220px;
  }
  .radio-div {
    min-width: 220px;
  }
  .long-text {
    .el-input__inner {
      min-width: 545px;
    }
  }
}
</style>

<style scoped>
.table-bordered {
  border: 1px solid #ddd;
}
.table {
  width: 100%;
  max-width: 100%;
  margin-bottom: 20px;
}
th,
td {
  padding: 5px;
  border: 1px solid #ddd;
}
th {
  width: 200px;
}
td {
  width: 500px;
}
</style>
